import { tbList } from "../../utils/dataset/menu";

Page({
  data: {
    userInfo: null,
    tbList: null,
  },

  onLoad(options) {
    wx.hideHomeButton()
  },
  onShow() {
    wx.hideHomeButton()
    this.setUserInfo();
    this.setDbTable();
  },
  async setUserInfo() {
    const app = getApp();
    this.setData({ userInfo: app.globalData.userInfo });
  },
  async setDbTable() {
    if (this.data.userInfo.role_id != 0) {
      this.setData({ tbList: tbList.slice(1) })
    } else {
      this.setData({ tbList: tbList })
    }
  },
  onScan() {
    wx.scanCode({
      onlyFromCamera: true,
      success(r) {
        const KEY_CODE = 'DGQHqGSRQhqRF_RHQHhyda';
        if (r.result.startsWith(KEY_CODE)) {
          wx.navigateTo({
            url: `/pages/user/coupon/list?order_id=${r.result.substring(KEY_CODE.length)}`,
          })
        } else {
          wx.showToast({
            title: '二维码已失效',
            icon: 'none'
          })
        }
      },
      fail(r) {
        wx.showToast({
          title: r.errMsg,
          icon: 'none'
        })
      }
    })
  },
})